// cyy-unit/touch/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    ballTop: 500,
    screenHeight: 0,
    screenWidth: 0,
    showNav: false
  },

  ready: function () {
    var _this = this;
    wx.getSystemInfo({ 
      success: function (res) { 
       _this.setData({ 
        screenHeight: res.windowHeight, 
        screenWidth: res.windowWidth, 
       }); 
      } 
     });
     var _navbar = wx.getStorageSync('_navbar');
     if (!_navbar) {
      getApp().request({
        url: getApp().api.default.navbar,
        success: function(e) {
            0 == e.code && (_navbar = e.data);
            _this.setData({
              _navbar: _navbar
            })
        }
      });
     } else {
      this.setData({
        _navbar: _navbar
       })
     }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    ballMoveEvent: function (t) {
      // var _that = this;
      // var touchs = t.touches[0];
      // var pageX = touchs.pageX; 
      // var clientY = touchs.clientY; 
      // if (this.data.screenHeight - clientY <= 40) return;
      var num = t.touches[0].clientY;
      if (num % 5 == 0) {
        this.setData({
          ballTop: t.touches[0].clientY - 40
        })
      }
      
    },
    showNavBut: function () {
      var that = this;
      that.setData({
        showNav: !that.data.showNav
      })
    },
    TabClick: function (e) {
      var url = e.currentTarget.dataset.url;
      if (url.indexOf('pages/index/index') >= 0 ||
      url.indexOf('pages/cat/cat') >= 0 ||
      url.indexOf('pages/cart/cart') >= 0 ||
      url.indexOf('pages/posts/index') >= 0 ||
      url.indexOf('pages/user/user') >= 0
      ) {
          wx.switchTab({ url })
      } else {
          wx.navigateTo({
              url: url,
          });
      }
    },
  }
})
